package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id=#{id}")
    int countByCategoryId(Integer id);

    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish (name, category_id, price, image, description, status,update_time,update_user,create_time,create_user) VALUES (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{updateTime},#{updateUser},#{createTime},#{createUser})")
    void add(Dish dish);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    Integer countByStatus(Long[] ids);


    void deleteByids(Long[] ids);

    @Select("select * from dish  where dish.id=#{id}")
    DishVO getById(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    List<Dish> list(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
